package springProvider.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.jgit.lib.PersonIdent;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.hutool.core.util.RandomUtil;
import hardy.grpc.helper.server.target.spring.RpcProvider;
import test.common.inface.OpeDatas;
import test.common.model.Humman;
import test.common.model.PersonU;
import test.common.model.Type;

@RpcProvider
@Service
@Transactional
public class DataImplent implements OpeDatas{

	@Override
	public List<Map<String, String>> createData(int size) {
		if(size%2==0) return null;
		List<Map<String, String>> list = new ArrayList<>();
		for(int i=0;i<size;i++) {
			Map<String,String> map = new HashMap<String, String>();
			for(int j=0;j<5;j++) {
				map.put(RandomUtil.randomString(3), RandomUtil.randomString(5));
			}
			list.add(map);
		}
		return list;
	}

	@Override
	public int[] createDataInt(int size) {
		return org.hardy.util.randomutil.RandomUtil.getRandomIntArray(size);
	}

	@Override
	public int plusData(int param1, int param2) {
		if(param1==100)
			try {
				Thread.sleep(30*1000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		return param1+param2;
	}

	@Override
	public double plusData(double param1, double param2) {
		return param1+param2;
	}

	@Override
	public boolean isLg(int param1, int param2) {
		return param1>param2;
	}

	@Override
	public Map<String, Humman> getMapStr() {
		 Map<String,Humman> map = new HashMap<String, Humman>();
		 for(int i=0;i<10;i++) {
			 Humman h = new Humman();
			 h.setName(RandomUtil.randomString(3));
			 h.setAge(RandomUtil.randomInt(100));
			 PersonU p = new PersonU();
			 p.setPerUid(String.valueOf(i+" oooooo"));
			 h.setPu(p);
			 h.getListPu().add(p);
			 if(i%2==0)h.setType(Type.A);
			 else h.setType(Type.B);
			 map.put(String.valueOf(i), h);
		 }
		 
		return map;
	}

	@Override
	public Map<String, Integer> getMapInt() {
		 Map<String,Integer> map = new HashMap<String, Integer>();
		 for(int i=0;i<10;i++) {
			 map.put(String.valueOf(i), i);
		 }
		return map;
	}

}
